package com.small.db;


import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.small.commom.Common;

public class DBOpenHelper extends SQLiteOpenHelper {
	private static String dbname = Common.DB_NAME;
	private static int version = Common.DB_VERSION;
	
	public DBOpenHelper(Context context)
	{
        super(context, dbname, null, version); 
	}
	
	public DBOpenHelper(Context context,String name,CursorFactory factory,int verson)
	{
	    super(context, name, factory, version);
	}

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        db.execSQL("CREATE TABLE IF NOT EXISTS tbPro(id integer,name varchar(10))");
        db.execSQL("CREATE TABLE IF NOT EXISTS tbCity(id integer,name varchar(10),proId integer)");
        db.execSQL("CREATE TABLE IF NOT EXISTS tbArea(id integer,name varchar(10),cityId integer)");
        db.execSQL("CREATE TABLE IF NOT EXISTS tbClass(SortID integer,SortName varchar(10))");
        //商户类别 表
        db.execSQL("CREATE TABLE IF NOT EXISTS tbShopType(CategoryID integer,CategoryName varchar(20),Letter varchar(10))");
        //商户类别子 表
        db.execSQL("CREATE TABLE IF NOT EXISTS tbShopTypeC(pid integer,CategoryID integer,CategoryName varchar(20),Letter varchar(10))");
        
      //商户类别 表
        db.execSQL("CREATE TABLE IF NOT EXISTS tbSQ(CategoryID integer,CategoryName varchar(20),Letter varchar(10))");
        //商户类别子 表
        db.execSQL("CREATE TABLE IF NOT EXISTS tbSQC(pid integer,CategoryID integer,CategoryName varchar(20),Letter varchar(10))");
    
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int arg1, int arg2)
    {
        onCreate(db); 
    }
    
    public Cursor select(String table, String[] columns, String whereClause, String order)
    {
        SQLiteDatabase database = this.getReadableDatabase();
        Cursor cursor = database.query(table, columns, whereClause, null, null, null, order);
        return cursor;
    }
    public int getCount(String table){
    	SQLiteDatabase database = this.getReadableDatabase();
        Cursor cursor = database.query(table, null, "", null, null, null, "");
    	return cursor.getCount();
    }
    public void myExecSql(String strSql)
    {
        SQLiteDatabase database = this.getWritableDatabase();
        database.beginTransaction();
        database.execSQL(strSql);
        database.setTransactionSuccessful();
        database.endTransaction();
    }
    public void onDelete(String tb)
    {
        SQLiteDatabase database = this.getWritableDatabase();
        database.delete(tb, null, null);
        database.close();
    }
    
    
}
